﻿$(function(){
    
    $('.corner').jQCornners({'cornerClass' : 'cornered'});
    $('#nav').jQCornners({'cornerClass' : 'cornered'});
    
    $(document).ajaxComplete(function(){ 
    
        $('#sku-selector ul.Cor li.select label').each(function(){
            
            var colorName =  $(this).text();
            colorName = colorName.toLowerCase();
            colorName = colorName.replace(new RegExp('[áàâã]','gi'), 'a');
            colorName = colorName.replace(new RegExp('[éèê]','gi'), 'e');
            colorName = colorName.replace(new RegExp('[íìî]','gi'), 'i');
            colorName = colorName.replace(new RegExp('[óòôõ]','gi'), 'o');
            colorName = colorName.replace(new RegExp('[úùû]','gi'), 'u');
            colorName = colorName.replace(new RegExp('[ç]','gi'), 'c');
            colorName = colorName.replace(new RegExp('[\ \)\(\_]', 'gi'), '-');
            colorName = colorName.replace(new RegExp('[^a-z0-9\-]', 'gi'), '');
            
            $(this).css({ 'background' : 'url(/Control/ArquivoExibir.aspx?NomeArquivo=prodcor-' + colorName + '.png) 0 0 no-repeat' });
            $(this).attr({ 'title' : $(this).text() });
            
            if ( $(this).find('.mask').size() == 0 ){
                $(this).append('<span class="mask"></span>');
            }
            
        });
        
        // Montando a listagem de comentários
        if ( $('#comments .commentsinner:empty').size() > 0 ) {
        
            $('#ulPubliqueResenha').prependTo('#comments');
            $('#resenha .links-resenha-usuario, #userReviewReturnMessages, #resenha .resenhas').appendTo('#comments .commentsinner');
        
        }
        
        $(".adicionar-resenha input[type='text']").attr("value", "");
        $(".adicionar-resenha textarea").text("");
        
        $("#product-content #comments .resenhas .quem > li:last").css({"background": "none", "padding" : "0"});
        
        $("#lnkPubliqueResenha").attr("title", "Faça um comentário").text("Faça um comentário");
        
        $('a.giftlistcreate-nouser').attr('href','/Site/Login.aspx');
       
		$("#product-content #productrate #resenha #opiniao_de_usuario .user-review #publishUserReview form#formUserReview .header .content .adicionar-resenha fieldset .grp.fTitulo label").text("Título");
    $("#product-content #productrate #resenha #opiniao_de_usuario .user-review #publishUserReview form#formUserReview .header .content .adicionar-resenha fieldset .grp.fComentario label").text("Opinião");
	   
    });
	
    $("#product-content #productrate #resenha #opiniao_de_usuario .user-review #ulPubliqueResenha li a").live("click", function(){
        $(this).parents("#ulPubliqueResenha").css("display", "none");
    });
    
});

$("document").ready(function(){
    $("#product-content #productrate #resenha #opiniao_de_usuario .user-review #ulPubliqueResenha li a").text("Deixe um comentário");
    $("#rtAvaliacao_SavedRate .ratingStar").removeClass("filledRatingStar").addClass("emptyRatingStar");
    $("#rdoInteresse:checked").attr("checked", false);
    $("#btnReferAFriend").attr("value", "Enviar para um amigo");
    $("#product-content #product-information #addtolist .giftlistinsertsku").css("display", "block");
    $("#product-content #product-information #addtolist .giftlistinsertsku").append("<a href='#' class='select-label'>Adicionar a lista de desejos</a>");
    $("#product-content #product-information #addtolist .giftlistinsertsku > a.select-label").click(function(){
        return false;
    });
    
    $("#product-content #comments #ulPubliqueResenha").remove();
    $("#product-content #comments").prepend("<h2><span class='inner'>Comentários</span></h2>");
    
    $("#product-content #product-information #addtolist .giftlistinsertsku ul.giftlistinsertsku-lists").find("li").each(function(){
        var linkText = $(this).find("a").text().replace(/Adicionar a lista /gi, "");
        var spanText = $(this).find("span").remove();
        $(this).find("a").text(linkText);
        $(this).find("span").text(spanText);
        $(this).find("a").append($(this).find("span"));
    });
    
    if($("#any-view-like li").size() == 0){
        $("#any-view-like").css("display", "none");
    }
    
    var removeSelectionsRating = setTimeout(function(){
        $("#opcoes-avalie input:radio").each(function(){
            $(this).attr("checked", false);
        });
        
        $("#rtAvaliacao_SavedRate").attr("value", "0");
        $(".rating-avalie").find("span").each(function(){
            $(this).removeClass("filledRatingStar");
            $(this).addClass("emptyRatingStar");
        });
    }, 2000);
    
    $("#addtolist .giftlistinsertsku .select-label").click(function(){
        $(this).parent().find(".giftlistinsertsku-lists").slideToggle();
    });
    
    $("#addtolist .giftlistinsertsku .giftlistinsertsku-button").click(function(){
        $(this).parents("#addtolist").empty().append("<p>Produto adicionado a lista de desejos com sucesso!</p>");
    });
    
    /*$("#product-information .topic.Cor .select.skuList input:checkbox").change(function(){
        
        if(typeof(myJSONSkuSpecification) !== "undefined" && !$(this).next("label").hasClass("sku-picked")){
            var colorSkuId = $(this).val();
            for(var i = 0; i < myJSONSkuSpecification.combination.length; i++){
                if(myJSONSkuSpecification.combination[i].colorSkuId != null){
                    console.log(myJSONSkuSpecification.combination[i].colorSkuId);
                }
            }
        }
    });*/
    
    $("#btnCancelar, #btnEnviar").each(function(){
        if($(this).parents(".roundedButton").length == 0){
            $(this).wrap("<span class='roundedButton' />");
        }
    });
	
	
	$('#product-buy .buy-button').attr('href','javascript:alert("Selecione o modelo desejado")');
	
});